<template>
	<div class="front">
		<el-input v-model.trim="searchText" placeholder="输入关键字" style="margin: 10px 0!important"></el-input>
		<div class="table bj bg-white">
			<el-scrollbar style="height: 100%;">
				<el-table :data="tableData" border highlight-current-row @row-dblclick="dblClick">
					<el-table-column property="name" label="名称" width="150" align="center"></el-table-column>
					<el-table-column property="bankName" label="开户行" width="200" align="center"></el-table-column>
					<el-table-column property="accountNumber" label="账号" align="center"></el-table-column>
				</el-table>
			</el-scrollbar>
		</div>
	</div>
</template>
<script>
export default {
	data() {
		return {
			searchText: '',
			tableData: []
		}
	},
	watch: {
		searchText(newVal) {			//搜索
			if(newVal) {
				let newArr = [],
					tableData = this.tableData;
				if(tableData.length > 0) {
					tableData.forEach(item => {
						if(item['name'].indexOf(newVal) > -1 || item['bankName'].indexOf(newVal) > -1 || item['accountNumber'].indexOf(newVal) > -1) {
							newArr.push(item);
						}
					});
					this.tableData = newArr;
				}
			} else {
				this.getData();
			}
		}
	},
	methods: {
		getData() {
			this.$http.get('borrowingForm/findAuxiliaryInfoBank').then(res => {
                if(res.data.code == 20001) {
                    if(res.data.data) {
                        this.tableData = res.data.data;
                    }
                }
            });
		},
		dblClick(row) {
			this.$store.commit('borrowOrderStore/updateBankInfo', row);
			this.close();
		},
		close() {
			let index = parent.layer.getFrameIndex(window.name);    //先得到当前iframe层的索引
            parent.layer.close(index);
		}
	},
	created() {
		this.getData();
	}
}
</script>
<style scoped>
	.table {min-width: 580px;height: calc(100% - 60px);}
</style>